package com.prs.crm.vo.gantt;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 甘特图视图对象
 * @author prs.chenzhi
 *
 */
public class GanttTask implements java.io.Serializable{

	
	private static final long serialVersionUID = 1L;
	
	public static final int CONSTRAINTTYPE_SOON = 0;//尽早
	public static final int CONSTRAINTTYPE_LATE = 1;//尽可能晚
	public static final int CONSTRAINTTYPE_MUSTSTART = 2;//必须在ConstraintDate指定时间开始
	public static final int CONSTRAINTTYPE_MUSTFINISH = 3;//必须在ConstraintDate指定时间结束
	public static final int CONSTRAINTTYPE_EARLIERSTART = 4;//不要早于ConstraintDate开始
	public static final int CONSTRAINTTYPE_LATERSTART = 5;//不要晚于ConstraintDate开始
	public static final int CONSTRAINTTYPE_EARLIERFINISH = 6;//不要早于ConstraintDate结束
	public static final int CONSTRAINTTYPE_LATERFINISH = 7;//不要晚于ConstraintDate结束

	/**
	 * 编号
	 */
	private Integer uid;
	
	/**
	 * 任务名称 
	 */
	private String name;
	
	/**
	 * 层次，决定排序
	 * 一般情况下，请勿手工指定
	 */
	private Integer level;
	
	/**
	 * 任务开始时间
	 */
	private Date start;
	
	/**
	 * 任务结束时间
	 */
	private Date finish;
	
	/**
	 * 摘要
	 */
	private boolean summary;
	
	/**
	 * 里程碑
	 */
	private boolean milestone;
	
	/**
	 * 完成百分比
	 */
	private Integer percentComplete;
	
	/**
	 * 任务的限制类型
	 * 0	As soon as possible.
		1	As late as possible.
		2	Must start on; ConstraintDate is required
		3	Must finish on; ConstraintDate is required
		4	Start no earlier than; ConstraintDate is required
		5	Start no later than; ConstraintDate is required
		6	Finish no earlier than; ConstraintDate is required
		7	Finish no later than; ConstraintDate is required
	 */
	private Integer constraintType;
	
	
	/**
	 * 限制时间
	 */
	private Date constraintDate;
	
	
	/**
	 * 点击任务以后导向的地址
	 */
	private String linkUrl;
	
	/**
	 * 跟踪
	 */
	private BaseLine baseLine;
	
	
	/**
	 * 前置任务
	 */
	private List<PredecessorTask> predecessorTasks;

	
	/**
	 * 子任务
	 */
	private List<GanttTask> childrens;
	
	public GanttTask()
	{
		this.summary = false;
	}
	
	public GanttTask(Integer uid,String name)
	{
		this();
		this.uid = uid;
		this.name = name;
	}
	
	public GanttTask(Integer uid,String name,Date start,Date finish)
	{
		this(uid,name);
		this.start = start;
		this.setFinish(finish);
	}
	


	public void setUid(Integer uid) {
		this.uid = uid;
	}


	public Integer getUid() {
		return uid;
	}


	public void setName(String name) {
		this.name = name;
	}


	public String getName() {
		return name;
	}


	public void setLevel(Integer level) {
		this.level = level;
	}

	public Integer getLevel() {
		return level;
	}


	public void setStart(Date start) {
		this.start = start;
	}


	public Date getStart() {
		return start;
	}



	public void setPercentComplete(Integer percentComplete) {
		this.percentComplete = percentComplete;
	}


	public Integer getPercentComplete() {
		return percentComplete;
	}


	public void setSummary(boolean summary) {
		this.summary = summary;
	}


	public boolean isSummary() {
		return summary;
	}


	public void setConstraintType(Integer constraintType) {
		this.constraintType = constraintType;
	}


	public Integer getConstraintType() {
		return constraintType;
	}


	public void setLinkUrl(String linkUrl) {
		this.linkUrl = linkUrl;
	}


	public String getLinkUrl() {
		return linkUrl;
	}

	public void setFinish(Date finish) {
		this.finish = finish;
	}

	public Date getFinish() {
		return finish;
	}

	public void setChildrens(List<GanttTask> childrens) {
		this.childrens = childrens;
	}

	public List<GanttTask> getChildrens() {
		return childrens;
	}
	
	public void setBaseLine(BaseLine baseLine) {
		this.baseLine = baseLine;
	}

	public BaseLine getBaseLine() {
		return baseLine;
	}



	public void addChild(GanttTask task)
	{
		if (this.childrens==null)
			this.childrens = new ArrayList<GanttTask>();
		if (!childrens.contains(task))
			childrens.add(task);
	}
	
	public void addPredecessorTask(PredecessorTask task)
	{
		if (this.predecessorTasks==null)
			this.predecessorTasks = new ArrayList<PredecessorTask>();
		this.predecessorTasks.add(task);
	}
	

	
	@Override
	public boolean equals(Object o)
	{
		if (o instanceof GanttTask)
		{
			if (((GanttTask)o).getUid().equals(this.uid))
				return true;
		}
		return false;
	}

	public void setConstraintDate(Date constraintDate) {
		this.constraintDate = constraintDate;
	}

	public Date getConstraintDate() {
		return constraintDate;
	}

	public void setPredecessorTasks(List<PredecessorTask> predecessorTasks) {
		this.predecessorTasks = predecessorTasks;
	}

	public List<PredecessorTask> getPredecessorTasks() {
		return predecessorTasks;
	}

	public void setMilestone(boolean milestone) {
		this.milestone = milestone;
	}

	public boolean isMilestone() {
		return milestone;
	}

}
